package com.bailan.foreat.utils;


import java.io.*;
import java.util.List;

public class TextWrite {
    //增加店铺、商品信息时调用本类方法,路径改为自己的

    static String path = "F:\\elasticsearch-7.17.6-windows-x86_64\\elasticsearch-7.17.6\\plugins\\elasticsearch-analysis-ik-7.17.6\\config\\my_extra_words.dic";

    public static void textWrite(String str) {
        try {
            //文件加内容
            FileReader fileReader = new FileReader(path);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line = "";
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line + "\r\n");
            }
            bufferedReader.close();

            stringBuilder.append(str + "\r\n");

            FileWriter fileWriter = new FileWriter(path);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            bufferedWriter.write(String.valueOf(stringBuilder).trim());
            bufferedWriter.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void textWrite(List<String> strArr) {
        try {
            //文件加内容
            FileReader fileReader = new FileReader(path);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line = "";
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line + "\r\n");
            }
            bufferedReader.close();

            for (String str : strArr) {
                stringBuilder.append(str + "\r\n");
            }

            FileWriter fileWriter = new FileWriter(path);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            bufferedWriter.write(String.valueOf(stringBuilder).trim());
            bufferedWriter.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
